home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Games Extra 1996 September
/
Amiga Games Extra CD-ROM 9-1996.iso
/
userbox
/
publicdomain
/
wbstars
/
source
/
wbstars_sys.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-09
|
6KB
|
304 lines
/* $VER: WBStars_sys.c 1.23 (09.07.1996) */
#include "WBStars_include.h"
#include "WBStars_protos.h"
#include "WBStars_gui.h"
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *CxBase;
struct DosLibrary *DOSBase;
struct Library *GadToolsBase;
struct Library *DiskfontBase;
struct Library *UtilityBase;
struct Screen *Screen;
struct Window *wnd;
struct RastPort *RastP;
short maxx;
short maxy;
char gui=FALSE;
char idcmp=0;
short anzcolors;
char GetWindow()
{
char ok=FALSE;
ULONG lock;
char locked=TRUE;
lock=LockIBase(0);
Screen = IntuitionBase->FirstScreen;
if( ! strcmp(Screen->DefaultTitle,"Workbench Screen") )
{
if( mode==MODE_WIN )
{
wnd=Screen->FirstWindow;
if( wnd )
{
do
{
if( (wnd->Flags&WFLG_BACKDROP) && (wnd->Flags&WFLG_BORDERLESS) && (wnd->Flags&WFLG_WBENCHWINDOW) )
{
ok=TRUE;
RastP = wnd->RPort;
anzcolors = (short)(1<<(RastP->BitMap->Depth));
maxx = wnd->Width;
maxy = wnd->Height;
UnlockIBase(lock);
locked=FALSE;
bgpen=bgpen%anzcolors;
if(gui) SetGadgets();
NewStars();
}
else
{
wnd=wnd->NextWindow;
}
}while( !ok && wnd );
}
}
else
{
ok=TRUE;
RastP = &(Screen->RastPort);
anzcolors = (short)(1<<(RastP->BitMap->Depth));
maxx = Screen->Width;
maxy = Screen->Height;
UnlockIBase(lock);
locked=FALSE;
bgpen=bgpen%anzcolors;
if(gui) SetGadgets();
NewStars();
}
}
if(locked)
{
UnlockIBase(lock);
}
return ok;
}
char WinWait()
{
ULONG lock;
char scrn;
lock=LockIBase(0);
scrn=(char)(IntuitionBase->FirstScreen!=Screen);
UnlockIBase(lock);
if( scrn||((mode==MODE_WIN)&& !CheckWindow2()) )
{
Delay( EVENT_WAIT );
ClearIfOk();
do
{
Delay( EVENT_WAIT );
}while( (CheckInteraction()==ACTIVE) && (GetWindow()==FALSE) );
}
return (char)(status==ACTIVE);
}
char CheckWindow2()
{
struct Window *wnd2;
ULONG lock;
lock=LockIBase(0);
wnd2=Screen->FirstWindow;
while( wnd2 && (wnd2!=wnd) )
{
wnd2=wnd2->NextWindow;
}
UnlockIBase(lock);
return (char)wnd2;
}
char CheckInteraction()
{
CxMsg *msg;
ULONG msgid, msgtype;
while(msg = (CxMsg *)GetMsg(broker_mp))
{
msgid = CxMsgID(msg);
msgtype = CxMsgType(msg);
ReplyMsg((struct Message *)msg);
switch(msgtype)
{
case CXM_COMMAND:
switch(msgid)
{
case CXCMD_DISABLE:
status=INACTIVE;
ClearIfOk();
Screen=NULL;
wnd=NULL;
ActivateCxObj(broker, 0L);
break;
case CXCMD_ENABLE:
status=ACTIVE;
ActivateCxObj(broker, 1L);
break;
case CXCMD_KILL:
status=QUIT;
ClearIfOk();
if( gui )
{
CloseWBStarsWindow();
CloseDownScreen();
}
break;
case CXCMD_UNIQUE:
if( !gui )
{
gui=OpenWBStarsWindow2();
}
else
{
WindowToFront(WBStarsWnd);
}
break;
case CXCMD_APPEAR:
if( !gui )
{
gui=OpenWBStarsWindow2();
}
else
{
WindowToFront(WBStarsWnd);
}
break;
case CXCMD_DISAPPEAR:
if( gui )
{
gui=FALSE;
CloseWBStarsWindow();
CloseDownScreen();
}
break;
}
break;
}
}
if( gui )
{
HandleWBStarsIDCMP();
if( idcmp )
{
switch(idcmp)
{
case IDC_HIDE:
gui=FALSE;
CloseWBStarsWindow();
CloseDownScreen();
break;
case IDC_QUIT:
status=QUIT;
ClearIfOk();
CloseWBStarsWindow();
CloseDownScreen();
break;
}
idcmp=0;
}
}
return status;
}
void ClearIfOk()
{
struct Screen *screen2;
char i;
ULONG lock;
if((mode==MODE_SCREEN)||CheckWindow2())
{
lock=LockIBase(0);
screen2=IntuitionBase->FirstScreen;
while( screen2 && (screen2!=Screen) )
{
screen2=screen2->NextScreen;
}
UnlockIBase(lock);
if( screen2 )
{
for(i=0; i<anzstars; i++)
{
ClearStar(i);
}
}
}
}
char OpenWBStarsWindow2()
{
char ret=FALSE;
if( SetupScreen()==0 )
{
if(OpenWBStarsWindow()==0)
{
ret=TRUE;
SetGadgets();
}
else
{
CloseDownScreen();
}
}
return ret;
}
void SetGadgets()
{
GT_SetGadgetAttrs(WBStarsGadgets[GD_azimut],WBStarsWnd,NULL,GTNM_Number,az,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_height],WBStarsWnd,NULL,GTNM_Number,he,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_azimut2],WBStarsWnd,NULL,GTIN_Number,az2,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_height2],WBStarsWnd,NULL,GTIN_Number,he2,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_mode_win],WBStarsWnd,NULL,GTCB_Checked,(mode==MODE_WIN),TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_warp],WBStarsWnd,NULL,GTSL_Level,warpf,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_pri],WBStarsWnd,NULL,GTSL_Level,wbs_pri,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_stars],WBStarsWnd,NULL,GTSL_Level,anzstars,TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_status],WBStarsWnd,NULL,GTCY_Active,(status==INACTIVE),TAG_DONE);
GT_SetGadgetAttrs(WBStarsGadgets[GD_bg_set],WBStarsWnd,NULL,GTIN_Number,bgpen,TAG_DONE);
}
char OpenLibraries()
{
CxBase = (struct Library*) OpenLibrary("commodities.library", 37L);
GadToolsBase = (struct Library*) OpenLibrary("gadtools.library", 0);
DiskfontBase = (struct Library*) OpenLibrary("diskfont.library", 0);
UtilityBase = (struct Library*) OpenLibrary("utility.library", 0);
DOSBase = (struct DosLibrary*) OpenLibrary("dos.library", 0);
IntuitionBase = (struct IntuitionBase*) OpenLibrary("intuition.library",0);
GfxBase = (struct GfxBase*) OpenLibrary("graphics.library",0);
if( !IntuitionBase||!GfxBase||!CxBase||!GadToolsBase||!DiskfontBase||!UtilityBase||!DOSBase )
return FALSE;
return TRUE;
}
void CloseLibraries()
{
if(IntuitionBase) CloseLibrary((struct Library*)IntuitionBase);
if(GfxBase) CloseLibrary((struct Library*)GfxBase);
if(CxBase) CloseLibrary( CxBase );
if(DOSBase) CloseLibrary((struct Library*)DOSBase);
if(GadToolsBase) CloseLibrary( GadToolsBase );
if(DiskfontBase) CloseLibrary( DiskfontBase );
if(UtilityBase) CloseLibrary( UtilityBase );
}